<!DOCTYPE HTML>
<html>
<head>
<?php
	include("components/helper.php");
	include("components/metadata.php");
?>
<title>40Towers - The Cast</title>
<link rel="stylesheet" href="css/global.css" />
<link rel="stylesheet" href="css/thecast.css" />
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<?php
	include("components/analytics.php");
	include("components/database.php");	
?>
</head>
<body>

<div id="page">
    <?php
		include("components/header.php");
		include("components/nav.php");
	?>
    
    <div>
    <section class="group">
        <h1>The Cast</h1>
        <article>
        	<?php 
				for ( $seriesCount=1;  $seriesCount<=2;  $seriesCount++ ) {
			?>
            
            <h2>Series <?= $seriesCount; ?></h2>
            
        	<?php 
				for ( $episodeCount=1;  $episodeCount<=6;  $episodeCount++ ) {
					
					if ($result = $mysqli->query("
											SELECT e.title
											FROM Episode AS e
											WHERE e.episodeNo=$episodeCount
											AND e.seriesNo=$seriesCount")) 
					{ 
						$episodeTitle = mysqli_fetch_array($result);
						$episodeTitle = $episodeTitle["title"];
					}
			?>
            
            <h3><?php echo $episodeCount; ?> - <?= $episodeTitle; ?></h3>
            
            <?php
					
				if ($result = $mysqli->query("
											SELECT a.id, a.actorName, a.actorSurname, a.dob, a.dod, 
												   e.seriesNo, e.episodeNo, e.title,
												   cm.castName, cm.castPhotoID, cm.cmID
											FROM Actor AS a, 
												 Episode AS e, 
												 ActorEpisode AS ae,
												 CastMember AS cm,
												 ActorCastMember AS acm
											WHERE 
												(ae.actorID=cm.cmID AND ae.episodeID=e.id)
												AND 
												(acm.actorID=a.id AND acm.castMemberID=cm.cmID)
												AND 
												(e.seriesNo=$seriesCount AND e.episodeNo=$episodeCount)
												
											ORDER BY e.seriesNo, e.episodeNo ASC")) 
				{
					while($obj = $result->fetch_object()){ 
						$id = $obj->id; 
						$name = $obj->actorName;
						$surname = $obj->actorSurname;
						$dob = $obj->dob;
						$dod = $obj->dod;
						$seriesNo = $obj->seriesNo;
						$episodeNo = $obj->episodeNo;
						$title = $obj->title;
						$castName = $obj->castName;
						$cmID = $obj->cmID;
			?>
        		
        		<h4><a href="profile_castmember.php?id=<?= $cmID; ?>&amp;episodeCount=<?= $episodeCount; ?>&amp;seriesCount=<?= $seriesCount; ?>"><?= replaceSpeechMarks($castName); ?></a><i> - 
                
                <a href="profile_actor.php?id=<?= $id; ?>"><?php echo replaceSpeechMarks($name) . " " . replaceSpeechMarks($surname); ?></a></i></h4>
                
                <!--
                <time datetime="<?= $dob; ?>">Born: <?= date('l jS \of F Y', strtotime($dob) ); ?></time>
                <?php
				if ( $dod ) {
                ?>
				<time datetime="<?= $dod; ?>">Died: <?= date('l jS \of F Y', strtotime($dod) ); ?>&nbsp;:(</time>
                <?php
				}
				?>
                //-->
                
        		
			<?php
						}
					}
                } 
            }
            ?>
        </article>
    </section>
    </div>
    
    <?php
		include("components/rightBanners.php");
	?>
</div>
<?php
	include("components/footer.php");
?>
</body>
</html>
